﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL.Entities;
using System.Data.SqlClient;

namespace DAL.EntitiesDAL
{
    public class ChucvuDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Chucvu");
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            var sql = "sp_Delete_Chucvu '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Chucvu)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Chucvu '{0}', N'{1}' ";
            sql = string.Format(sql, o.MACHUCVU, o.TENCHUCVU);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Chucvu)obj;
            var sql = "set dateformat dmy; execute sp_Update_Chucvu '{0}', N'{1}' ";
            sql = string.Format(sql, o.MACHUCVU, o.TENCHUCVU);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"Select * from tb_Chucvu";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }

        public DataTable Search(DAL.Entities.Chucvu o)
        {
            string sql;
            if (o.MACHUCVU != "")
                sql = @"Select * from tb_Chucvu Where MACHUCVU like '%" + o.MACHUCVU + "%'  ";
            else
                sql = @"Select * from tb_Chucvu Where TENCHUCVU like N'%" + o.TENCHUCVU + "%' ";

            return ExecuteQuery(sql);
        }


        #endregion
    }
}
